/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.service;

import br.ufc.quixada.adrs.dao.ContatoDAO;
import br.ufc.quixada.adrs.model.Contato;
import br.ufc.quixada.adrs.util.Msg;
import java.sql.SQLException;
import java.util.List;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Caio
 */
public class ContatoService {

    private final ContatoDAO dao = new ContatoDAO();

    public boolean insertContato(Contato contato) {
        try {
            dao.insert(contato);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean updateContato(Contato contato) {
        try {
            dao.update(contato);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean deleteContato(Long id) {
        try {
            dao.delete(id);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public Contato getContatoById(Long id) {
        try {
            Contato contato = dao.getById(id);
            return contato;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }

    public List<Contato> getContatosByUsuarioId(Long id) {
        try {
            List<Contato> contatos = dao.getByUsuarioId(id);
            return contatos;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }
}
